<?php
/**
 * Created by PhpStorm.
 * User: ywf
 * Date: 14-11-6
 * Time: 下午6:10
 */


/**
 * 遍历数组，相同属性的一组分开显示。有序数组
 */
$a = array(
    0 => array('num' => 1, 'type' => 'students'),
    1 => array('num' => 2, 'type' => 'students'),
    2 => array('num' => 5, 'type' => 'students'),
    3 => array('num' => 3, 'type' => 'worker'),
    4 => array('num' => 4, 'type' => 'dancer'),
);

$temp = '';
foreach ($a as $key => $v) {
    if ($v['type'] <> $temp) {
        $temp = $v['type'];
        echo $v['type'] . '<br>';
    }
    echo $v['num'] . '<br>';

    /*方法二
     *  if(!in_array($v['type'],$temp)){
          $temp[]=$v['type'];
          echo $v['type'].'<br>';
      }*/
}
var_dump($a);
/**
 * 数值转换
 */


/*纵向数列转换成横向数列
比如array(array(1,2,3,4),array(5,6,7,8),array(9,10,11,12));
转换成array(array(1,5,9),array(2,6,10),array(3,7,11),array(4,8,12))*/

